<template>
	<view>
		<u-navbar back-icon-color="#fff" :isFixed="true" :border-bottom="false" title="选择试卷" title-color="#FFFFFF">
			<template v-slot:right>
				<text class="confirm" v-if="dataList.length!=0" @click="submit">确定</text>
			</template>
		</u-navbar>
		<my-serch @onchange="inputChange"></my-serch>
		<my-empty v-if="emptyFalse"  emptyTit="暂无试卷记录哦~"></my-empty>
		<view class="examContent">
			<view v-for="(paper,index) in dataList" :key="paper.paperid" class="examPaper" @click="examChose(paper,index)" :class="[choseIndex==index?'hoverBg':'']">
				<view class="paper-item">
						<view class="name">
							<view class="content">{{paper.papername}}</view>
							<view class="name_bot">
								<view class="name_bot_l"><my-icon name="time"></my-icon><text>创建时间：{{paper.createtime}}</text></view>
							</view>
						</view>
				</view>
			</view>
		</view>
		<my-confirm ref="headBack" @cancel="backCancel()" @confirm="backSubmit()" confirm-text="确定" cancel-text="取消">
			<view class="subModal">
				<view class="subModalTit">确定放弃当前的操作，开始创建试卷</view>
			</view>
		</my-confirm>
		<!-- 悬浮按钮 -->
		<view class="slideNav" @click="creatExam"><my-icon name="fabukaoshi"></my-icon></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: {},
				choseIndex:null,//选中
				paperid:null,//选中的试卷
				emptyFalse:false
			}
		},
		onLoad(){
			this.init()
		},
		onShow(){
			this.init()
		},
		methods: {
			init(){
				this.examList=[];
				return this.getExamList();
			},
			inputChange(e){
				this.getExamList(e)
			},
			//创建试卷按钮
			creatExam(){
				this.$nextTick(function() {
					this.$refs.headBack.open();
				});
			},
			// 确定弹窗
			backSubmit(){
			  uni.navigateTo({
			   	url:"../paperManagement/paperManagement?linkType=1"
			   })
				 this.$nextTick(function() {
				 	this.$refs.headBack.close();
				 });
			},
			//取消弹窗
			backCancel(){
				this.$nextTick(function() {
					this.$refs.headBack.close();
				});
			},
			//选择当前考试
			examChose(item,index){
				this.choseIndex=index
				this.paperid=item.paperid
			},
			// 确定进入下一步
			submit(){
				if(this.choseIndex!=null){
					//获取存储的值，并新增
				 const sess=uni.getStorageSync('examStorage')
				 sess.paperid=this.paperid
				 uni.setStorageSync('examStorage', sess)
				 uni.navigateTo({
				  	url:"examSelectType"
				  })
				}else{
					uni.showToast({
						duration: 1000,
						title: "请选择试卷",
						icon: "none"
					})
				}
			},
			//获取列表
			getExamList(papername){
				this.status = 'loading';
				const pageData={
					'papertype':1,
					'papername':papername
				}
				return new Promise((resolve, reject) => {
					this.request
						.get('/app/teacher/releaseExam/getPaperList',pageData)
						.then(res => {
							this.dataList = res;
							this.emptyFalse=this.dataList.length>0?false:true
							resolve();
						})
						.catch(reject)
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.empty{
		height: 90%;
		top: auto;
	}
	.examPaper:last-child .paper-item{
		border-bottom: none;
	}
	.examPaper .paper-item{
		border-bottom: 1px solid #EBEBEB;
	}
	.subModalTit{font-size:30upx;color: #363940;}
   .slideNav{
		 position: fixed;
		 bottom: 50upx;
		 right: 30upx;
		 width: 100upx;
		 height: 100upx;
		 border-radius: 100upx;
		 text-align: center;
		 line-height: 100upx;
		 background: linear-gradient( #FC7767 0%, #EC412F 100%);
		 box-shadow: 0px 3upx 14upx 0px rgba(244,92,75,0.4);
		 .iconfont{
			 color: #fff;
			 font-size: 36upx;
		 }
	 }
	 .name_bot{
		 .name_bot_l{ width: 100%;
		    text{
				 	margin-left: 0;
		 		   max-width: 600upx;
		    }
		 }
	 }
</style>
